//
//  HTRecentPlayCell.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/13.
//

import SwiftUI

struct HTRecentPlayCell: View {

  var var_anime: HTAnime = HTAnime()
  var var_isEdit: Bool = false
  var var_isSel: Bool = false
  var var_onSel: ((HTAnime) -> Void)? = {anime in}
  var var_onMore: ((HTAnime) -> Void)? = {anime in}

  var body: some View {
    VStack(alignment: .leading) {
      HStack(spacing: 10){
        if (var_isEdit) {
          HStack {
            if (var_isSel) {
              HStack{
                Image("sel")
                  .frame(width: 10, height: 8)
              }
              .frame(width: 22, height: 22)
              .background(Color(hex: "#FF6C3C"))
              .clipShape(Capsule())
              .onTapGesture {
                var_onSel!(var_anime)
              }
            } else {
              HStack{
                Image("nosel")
                  .frame(width: 22, height: 22)
              }
              .onTapGesture {
                var_onSel!(var_anime)
              }
            }
          }
          .padding(.trailing, 5)
        }

        HTCoverView(var_anime: var_anime, var_width: UIDevice.ht_fixToWidth(width: 76), var_height: UIDevice.ht_fixToWidth(width: 112))
        VStack(alignment: .leading, spacing: 4){
          Text(var_anime.var_title ?? "")
            .foregroundColor(Color(hex: "#393939"))
            .font(.system(size: UIDevice.ht_fixToWidth(width: 14)))
            .fontWeight(.bold)
            .lineLimit(2)
            .lineSpacing(5)
            .multilineTextAlignment(.leading)
            .frame(maxWidth: .infinity, alignment: .topLeading)
          Text("\(var_anime.var_cur_ep ?? "") | Watched \(var_anime.ht_progressStr())")
            .font(.system(size: UIDevice.ht_fixToWidth(width: 10)))
            .lineLimit(1)
            .foregroundColor(Color(hex: "#999999"))
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
        .padding(.top, 5)
        Spacer()

        if (!var_isEdit) {
          HStack{
            Image("more_v")
              .frame(width: 22, height: 22)
          }
          .onTapGesture {
            var_onMore!(var_anime)
          }
        }
      }
      .padding(.trailing, 15)
      .padding(.vertical, 15)
    }
    .frame(maxWidth: .infinity)
    .padding(.leading, 15)
    .background(Color.white)
    .cornerRadius(UIDevice.ht_fixToWidth(width: 8))
  }
}
